﻿using System;
using System.Linq.Expressions;
using _5E.Infrastructure.Expression;

namespace _5E.Infrastructure.Querying
{
    public class OrderByClause
    {
        private string m_PropertyName = null;
        public string PropertyName
        {
            get { return m_PropertyName; }
            set { m_PropertyName = value; }
        }

        private bool m_Asc = true;
        public bool Asc
        {
            get { return m_Asc; }
            set { m_Asc = value; }
        }

        public OrderByClause(string propertyName, bool asc)
        {
            PropertyName = propertyName;
            Asc = asc;
        }

        public static OrderByClause Create<T>(Expression<Func<T, object>> expression, bool asc = true)
        {
            string propertyName = PropertyNameHelper.ResolvePropertyName<T>(expression);
            return new OrderByClause(propertyName, asc);
        }
    }
}
